<template>
  <div class="WorkingSchedule" v-loading="loading">
    <!-- <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="款号" class="myform-item">
          <el-input
            v-model="form.product_code"
            placeholder="请输入款号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="申请日期">
          <el-date-picker
            value-format="yyyy-MM-dd"
            v-model="date"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px">
          <el-button @click="onSearch" type="primary">查询</el-button>
          <el-button type="primary">导出</el-button>
          <el-button type="primary">上传文件</el-button>
        </el-form-item>
      </div>
    </el-form> -->
    <el-table :data="tableData" style="width: 100%" border>
      <template v-for="(item, index) in tableHeader">
        <el-table-column
          :label="item.name"
          :key="index"
          align="center"
          :prop="item.key"
        >
        </el-table-column>
      </template>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postApigift"
    />
  </div>
</template>

<script>
import { postApigift } from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      date: "",
      form: {
        product_code: "",
        strtime: "",
        endtime: "",
        page: 1,
        size: 10,
      },
      tableHeader: [
        {
          name: "款号",
          key: "type_no",
        },
        {
          name: "商品编码",
          key: "product_code",
        },
        {
          name: "商品名称",
          key: "product_name",
        },
        {
          name: "数量",
          key: "sum",
        }
      ],
      tableData: [],
      total: 1,
    };
  },
  activated() {
    let form = this.form;
    this.postApigift(form);
  },
  methods: {

    // 编辑
    onEdit(e) {
      console.log("编辑", e);
      this.detail = e;
      this.dialogVisible = true;
    },
    // 采购列表
    async postApigift(data) {
        this.loading = true
      this.form = data;
      postApigift(data).then((res) => {
          this.loading = false
        console.log("采购列表", res);
        this.tableData = res.data;
        this.total = Number(res.total);
      }).catch(err=>{
          this.loading = false
      })
    },
    // 搜索
    onSearch() {
      let date = this.date;
      if (date) {
        this.form.strtime = date[0];
        this.form.endtime = date[1];
      }
      this.form.page = 1 
      this.form.size = 10
      this.postApigift(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
